package com.lingo.a2b.response;

import lombok.Data;

import java.io.Serializable;

/**
 * @author lingo
 * @date 2020/2/16 17:20
 * @Company: www.xyb2b.com
 */
@Data
public class MyResponse<T> implements Serializable {

    public static final int SUCCESS = 200;
    public static final int FAIL = 500;
    public static final String SUCCESS_MSG = "ok";
    public static final String ERROR_MSG = "fail";

    private static final long serialVersionUID = 8334508714867058198L;

    private int retCode;
    private String retMsg;
    private T retEntity;

    public MyResponse() {
    }

    public MyResponse(int retCode, String retMsg, T retEntity) {
        this.retCode = retCode;
        this.retMsg = retMsg;
        this.retEntity = retEntity;
    }

    public static <T> MyResponse<T> success(T retEntity){
        return new MyResponse<T>(SUCCESS,SUCCESS_MSG,retEntity);
    }

    public static  MyResponse<String> fail(){
       return new MyResponse<>(FAIL,ERROR_MSG,null);
    }

    public static MyResponse<String> fail(String retMsg){
        return new MyResponse<>(FAIL,retMsg,null);
    }

    public static MyResponse<String> fail(int retCode, String retMsg){
        return new MyResponse<>(retCode,retMsg,null);
    }

    public boolean isFail(){
        return this.retCode != SUCCESS;
    }
}
